﻿using System;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace ZoambieGaem
{
    class Projectile
    {
        public int width;
        public int height;
        public int centerX;
        public int centerY;
        public float angle;
        public int range;
        public Vector2 worldPosition;
        public double speed;
        public int damage;
        public int type;

        public Projectile(Master m, int type, float projectileAngle) {
            this.type = type;
            this.speed = Weapons.getSpeed(this.type);
            this.range = Weapons.getRange(this.type);
            this.damage = Weapons.getDamage(this.type);

            this.angle = projectileAngle;
            this.width = (int)(Weapons.getTexture(this.type).Width * m.drawScale);
            this.height = (int)(Weapons.getTexture(this.type).Height * m.drawScale);
            this.centerX = Weapons.getTexture(this.type).Width / 2;
            this.centerY = Weapons.getTexture(this.type).Height / 2;
            this.worldPosition = m.player.worldPosition;
        }

        public void nextPos() {
            this.worldPosition = 
                new Vector2(this.worldPosition.X + (float)(Math.Cos(this.angle) * this.speed),
                            this.worldPosition.Y + (float)(Math.Sin(this.angle) * this.speed));
        }

        public Boolean update(Master m) {

            Boolean valid = true;
            if (m.frameDrawn) {
                nextPos();

                this.range -= 1;

                int x = (int)(this.worldPosition.X / m.blockSize);
                int y = (int)(this.worldPosition.Y / m.blockSize);

                if (this.worldPosition.X < 0 || x >= Maps.width)
                    valid = false;

                if (this.worldPosition.Y < 0 || y >= Maps.height)
                    valid = false;

                if (valid && Maps.map[y][x] == 1)
                    valid = false;

                if (range <= 0)
                    valid = false;

                if (speed <= 0)
                    valid = false;
            }
            return valid;

        }
    }
}